﻿/* */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

using NUnit.Framework;
using SourceGrid;
using SourceGrid.Cells;

namespace SourceGrid.Tests
{
	[TestFixture]
	public class TestGridVirtual_PositionToRectangle
	{
		[Test]
		public void PositionToCellRange()
		{
			Assert.AreEqual(Rectangle.Empty, new Grid().PositionToRectangle(new Position(10, 10)));
		}
	}
	
	
	[TestFixture]
	public class TestDataGrid_PositionToCellRange
	{
		[Test]
		public void PositionToCellRange_OutOfBounds()
		{
			DataGrid grid1 = new DataGrid();
			List<int> list = new List<int>();
			grid1.DataSource = new DevAge.ComponentModel.BoundList<int>(list);
			Assert.AreEqual(Range.Empty, grid1.PositionToCellRange(new Position(5, 5)));
		}
	}
	
	[TestFixture]
	public class TestGrid_Span
	{
		[Test]
		public void PositionToCellRange_OutOfBounds()
		{
			Grid grid1 = new Grid();
			grid1.Redim(0, 0);
			Assert.AreEqual(Range.Empty, grid1.PositionToCellRange(new Position(0, 0)));
		}
		
		[Test]
		public void PositionToCellRange()
		{
			Grid grid1 = new Grid();
			grid1.Redim(6, 6);

			grid1[0, 0] = new SourceGrid.Cells.Cell();
			grid1[0, 0].ColumnSpan = 3;
			grid1[0, 0].RowSpan = 3;
			
			Assert.AreEqual(new Range(0, 0, 2, 2), grid1.PositionToCellRange(new Position(0, 0)));
		}
		
		[Test]
		public void RangeToCellRange()
		{
			Grid grid1 = new Grid();
			grid1.Redim(6, 6);

			grid1[0, 0] = new SourceGrid.Cells.Cell();
			grid1[0, 0].ColumnSpan = 3;
			grid1[0, 0].RowSpan = 3;
			
			grid1[0, 3] = new SourceGrid.Cells.Cell();
			grid1[0, 3].ColumnSpan = 3;
			grid1[0, 3].RowSpan = 3;
			
			Assert.AreEqual(new Range(0, 0, 2, 5), grid1.RangeToCellRange(new Range(0, 0, 0, 3)));
		}
	}
	
	[TestFixture]
	public class TestGridVirtual_Clipboard
	{
		private Grid m_grid = null;
		private readonly int m_firstValue = 2;
		private readonly int m_secondValue = 5;
		
		[SetUp]
		public void SetUp()
		{
			m_grid = new Grid();
			m_grid.ClipboardMode = ClipboardMode.All;
			m_grid.Redim(2, 2);
			m_grid[0, 0] = new Cell(m_firstValue, typeof(int));
			m_grid[1, 1] = new Cell(m_secondValue, typeof(int));
			
			Assert.AreEqual(m_firstValue, m_grid[0, 0].Value);
			Assert.AreEqual(m_secondValue, m_grid[1, 1].Value);
		}
		
		[Test]
		public void PerformDelete()
		{
			m_grid.PerformDelete(new RangeRegion(new Range(0, 0, 1, 1)));
			Assert.AreEqual(0, m_grid[0, 0].Value);
			Assert.AreEqual(0, m_grid[1, 1].Value);
		}
		
		[Test]
		public void PerformCut()
		{
			m_grid.PerformCut(new RangeRegion(new Range(0, 0, 0, 0)));
			Assert.AreEqual(0, m_grid[0, 0].Value);
			
			m_grid.PerformPaste(new RangeRegion(new Range(1, 1, 1, 1)));
			Assert.AreEqual(m_firstValue, m_grid[1, 1].Value);
		}
		
		[Test]
		public void PerformCopyAndPaste()
		{
			m_grid.PerformCopy(new RangeRegion(new Range(0, 0, 0, 0)));
			m_grid.PerformPaste(new RangeRegion(new Range(1, 1, 1, 1)));
			Assert.AreEqual(m_firstValue, m_grid[1, 1].Value);
		}
	}
}
